import request from '@/utils/request';

export default function(repository) {
    return {
        fetchPage(query) {
            query.list = null;
            return request({
                url: '/' + repository + '/page',
                method: 'GET',
                params: query
            });
        },
        fetchAll() {
            return request({
                url: '/' + repository,
                method: 'GET'
            });
        },
        getEntity(id) {
            return request({
                url: '/' + repository + '/' + id,
                method: 'GET'
            });
        },
        postEntity(entity) {
            return request({
                url: '/' + repository,
                method: 'POST',
                data: JSON.stringify(entity)
            });
        },
        putEntity(entity) {
            return request({
                url: '/' + repository + '/',
                method: 'PUT',
                data: JSON.stringify(entity)
            });
        },
        deleteEntity(id) {
            return request({
                url: '/' + repository + '/' + id,
                method: 'DELETE'
            });
        },
        releaseEntity(id) {
            return request({
                url: '/' + repository + '/publish',
                method: 'POST',
                data: { id }
            });
        }
    };
}
